import axios,{ AxiosResponse } from 'axios'
import urlMap from "@/api/url_map";

// axios.defaults.baseURL = 'http://106.15.179.105:3000/'
axios.defaults.timeout = 5000

const request = (urlObj, params): Promise<AxiosResponse> => {
  const config = {
    url: urlObj.url,
    method: urlObj.type,
  };
  switch(config.method){
    case "GET":
      config.params = params;
      break;
    case "POST":
      config.data = params;
      break;
  }
  return axios({...config})
}


export const register = (params) => request(urlMap.register, params);
export const findUserName = (params) => request(urlMap.findUserName, params);
export const login = (params) => request(urlMap.login, params);
export const getAllProduct = (params) => request(urlMap.getAllProduct,params);
export const getBannerPicture = (params) => request(urlMap.carousel,params);

